//引入ajax
import { ajax } from "../../public/promiseAjax.js";
// 引入公共js
import * as obj from "../public.js";
// 
const o = obj.default;
// 创建点击事件
function regF(eve) {
  const e = eve || window.event;
  const target = e.target || e.srcElement;
  // 判断点击元素是不是登录按钮
if (target.className === 'reg') {
    const un = o.$('.un').value;
    const tel = o.$('.tel').value;
    const pw = o.$('.pw').value;
    const code = o.$('.code').value
    // ajax获取后端数据
    ajax({
      url: 'http://localhost:3000/register',
      method: 'post',
      data: {
        username: un,
        tel: tel,
        password: pw,
        code
      }
    }).then((res) => {
      const data = JSON.parse(res)
      // 成功之后
      if (data.state === 1) {
        location.href = 'http://10.11.55.120:3000/html/login.html'
      } else {
        alert(data.msg)
      }
    })
  }
}
export { regF }